home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / dialogic.zip / EXAMPLE1.BAS < prev    next >
BASIC Source File  |  1990-01-31  |  8KB  |  194 lines

  1. '
  2. '┌───────────────────────────────────────────────────────┐
  3. '│ Written by Jonathan S. Waldman                        │
  4. '│ (C) 1989, 1990 Jonathan S. Waldman & Dialog Software  │
  5. '│ (C) Crescent Software.                                │
  6. '│ All rights reserved.                                  │
  7. '└───────────────────────────────────────────────────────┘
  8.  
  9. '============
  10. 'DiaLogic
  11. 'EXAMPLE1.BAS
  12. '============
  13.  
  14. '$INCLUDE: 'DIALOGIC.BI'      'include our DiaLogic TYPE definitions
  15.  
  16. '===========================================================================
  17. 'This program demonstrates the use of a single-tasking unstacked dialog box,
  18. '  and shows that even though dialog boxes are unstacked, it does not mean
  19. '  they can't be fully-functional.
  20. '
  21. 'In this example program you may enter a search string and select various
  22. '  options.  If you choose <Help> a new dialog box will appear with help
  23. '  text.  When you are finished reading the help, you may close the dialog
  24. '  box by pressing <Enter>.  At this point, this program will re-generate
  25. '  the Find dialog box by filling it with all the options you chose before
  26. '  <Help> was requested.  The Find dialog box will continue to appear until
  27. '  Help is NOT chosen or until <Esc> is pressed.
  28. '
  29. 'Please notice that this example defines some strings for convenience and
  30. '  enhanced readability, such as ESC$ and Help$.  You should also notice
  31. '  that the Find template also includes these strings in the command button
  32. '  definitions.  Further, other variables, such as Search$ and WholeWord,
  33. '  are used to set a re-generated Find dialog box to its previously-set
  34. '  values.
  35. '===========================================================================
  36.  
  37. '====================
  38. 'Initialize the mouse
  39. '====================
  40.  
  41.    CALL InitMouse(There%)        'see if mouse and driver are there
  42.    IF There% THEN                'if yes then
  43.       CALL ShowCursor            'show the mouse
  44.       CALL TextCursor(0, 4)      'use this to insure mouse is always visible
  45.    END IF
  46.  
  47. '======
  48. 'Set-up
  49. '======
  50.  
  51.    CALL HideCursor
  52.    WIDTH , 25                    'insure we're in 25-line mode
  53.    COLOR 15, 1
  54.    CLS                           'clear the screen
  55.  
  56. '========================
  57. 'REDIM the arrays for now
  58. '========================
  59.  
  60.    '$DYNAMIC                     'make all arrays dynamic
  61.    MaxDBE = 20                   'use for our dimension statements
  62.                                  '  20 dialog box elements will be our max
  63.    REDIM SHARED DB(1, MaxDBE) AS DialogType  'REDIM these TYPE arrays
  64.    REDIM SHARED LB(0) AS DialogText          '  dynamically
  65.  
  66.  
  67. PRINT
  68. PRINT "   This is a single-tasking dialog box."
  69. PRINT
  70. PRINT "   Observe that <Help> closes the Find dialog box and removes it from the"
  71. PRINT "   screen and then generates a Help dialog box.  Note also that any"
  72. PRINT "   selections made on the Find dialog box (before help is requested) are"
  73. PRINT "   preserved when the Find dialog box is regenerated.  Help is NOT avail-"
  74. PRINT "   able with <F1> in this example."
  75. PRINT : PRINT
  76. CALL ShowCursor
  77.  
  78.  
  79. '=======================================
  80. 'Define some convenient string variables
  81. '=======================================
  82.  
  83.    Cancel$ = CHR$(27)            'these are our string assignments, also used
  84.    Help$ = CHR$(0) + CHR$(59)    '  in the FIND.DB template.
  85.    OK$ = CHR$(13)
  86.  
  87.    Search$ = ""                  'initialize Search$ to null
  88.    ExitLoop = 0                  'initialize our DO loop variable to 0
  89.  
  90. '=================
  91. 'start the DO loop
  92. '=================
  93.  
  94.    DO
  95.       '******************************************************************
  96.       
  97.       GOSUB FindDBSetUp          'prepare for the Find dialog box
  98.                                  '   then generate it by calling DiaLogic
  99.  
  100.       CALL DiaLogic(DB(), LB(), Action%, Focus%, Ky$)
  101.      
  102.       '******************************************************************
  103.  
  104.       '======================================================================
  105.       'When program execution returns here the dialog box already will have
  106.       'been cleared from the screen since Action 0 was used.  If <Help> is
  107.       'chosen we'll generate a Help dialog box.  We'll also check to see if
  108.       '<Esc> was pressed or if <OK> was entered, in which case we can get the
  109.       'search string and conduct a search.
  110.       '======================================================================
  111.  
  112.       'Now we can store dialog box information in local variables.  These
  113.       '  variables also appear in the template definition.  Level% will still
  114.       '  be 1.  Notice that the second subscript, the Sequence number, is
  115.       '  used to access information for particular dialog box elements in
  116.       '  the template.
  117.  
  118.       Search$ = MID$(DB(Level%, 2).TextString, 1, DB(Level%, 2).NumberOne)
  119.                                            'Search$ holds our search string
  120.       MatchCase = DB(Level%, 3).Default    '-1 if Match Case is checked
  121.       WholeWord = DB(Level%, 4).Default    '-1 if Whole Words is checked
  122.       SearchType = DB(Level%, 5).Default   ' 1 for Active Window, 2 for
  123.                                            ' Current Module, or 3 for
  124.                                            ' All Modules
  125.  
  126.       '====================================================================
  127.       'below we are processing the call to DiaLogic to see what was entered
  128.       'into the dialog box
  129.       '====================================================================
  130.  
  131.       SELECT CASE Ky$
  132.          CASE Cancel$               '<Cancel> pressed (the <Cancel> button
  133.                                     '  was defined to Esc$ in the template
  134.             PRINT "   You pushed <Cancel>."
  135.             ExitLoop = -1           'exit the do loop
  136.          CASE Help$
  137.  
  138.             '================================================================
  139.             'Since the user chose help we must generate another dialog box.
  140.             '  This time it will be a Help dialog box for the Find dialog
  141.             '  box.
  142.             '================================================================
  143.  
  144.             GOSUB HelpDBSetUp
  145.             CALL DiaLogic(DB(), LB(), Action%, Focus%, Ky$)
  146.          CASE OK$
  147.             PRINT "   You pushed <OK>."
  148.             ExitLoop = -1
  149.          CASE ELSE
  150.             BEEP                    'bad value returned
  151.       END SELECT
  152.    LOOP UNTIL ExitLoop
  153.  
  154.    '=======================================================================
  155.    'Print the results to the user.  This is for demonstration purposes only
  156.    '  to show that the calling program has correctly received information
  157.    '  from the dialog box.
  158.    '=======================================================================
  159.  
  160.    PRINT "   Your search string is " + LEFT$(Search$, 40) + " ..."
  161.    IF MatchCase THEN
  162.       PRINT "   Match Upper/Lower Case was checked."
  163.    END IF
  164.    IF WholeWord THEN
  165.       PRINT "   Whole Words Only was checked."
  166.    END IF
  167.    PRINT "   " + RTRIM$(MID$(DB(Level%, 5 + SearchType).Text, 5)) + " was selected."
  168.    COLOR 7, 0
  169.    CALL HideCursor
  170. END
  171.  
  172. '=============================
  173. 'Dialog box set-up subroutines
  174. '=============================
  175.  
  176. FindDBSetUp:
  177.    REDIM SHARED DB(1, MaxDBE) AS DialogType  'REDIM these TYPE arrays
  178.    REDIM SHARED LB(0) AS DialogText     '  dynamically
  179.    Level% = 1                    'set Level% to 1
  180.    '$INCLUDE: 'FIND.DB'          'include the Find dialog box template
  181.    Action% = 0                   'set Action% to 0
  182.    Focus% = 0                    'set the input focus to auto -- 0
  183.    RETURN
  184.  
  185. HelpDBSetUp:
  186.    REDIM SHARED DB(1, MaxDBE) AS DialogType  'REDIM these TYPE arrays
  187.    REDIM SHARED LB(10) AS DialogText
  188.    Level% = 1                    'set Level% to 1
  189.    '$INCLUDE: 'FINDH.DB'         'include Help dialog box template
  190.    Action% = 0                   'set Action% to 0
  191.    Focus% = 0                    'set the input focus to auto -- 0
  192.    RETURN
  193.  
  194.